package com.google.gwt.maps.v3.client.streetview;

import java.util.ArrayList;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.maps.v3.client.streetview.impl.StreetViewPanoramaDataImpl;

public class StreetViewPanoramaData implements HasStreetViewPanoramaData {

  private JavaScriptObject jso;
  
  public static final StreetViewPanoramaDataImpl impl = StreetViewPanoramaDataImpl.impl;
  
  public StreetViewPanoramaData(JavaScriptObject jso) {
    this.jso = jso;
  }
  
  public StreetViewPanoramaData() {
    this(impl.construct());
  }

  @Override
  public String getCopyright() {
    return impl.getCopyright(jso);
  }

  @Override
  public ArrayList<HasStreetViewLink> getLinks() {
    final ArrayList<HasStreetViewLink> links = new ArrayList<HasStreetViewLink>();
    final JsArray<JavaScriptObject> linksJso = impl.getLinks(jso);
    if (linksJso != null) {
      for (int i = 0; i < linksJso.length(); ++i) {
        final JavaScriptObject linkJso = linksJso.get(i);
        final HasStreetViewLink link = new StreetViewLink(linkJso);
        links.add(link);
      }
    }
    return links;
  }

  @Override
  public HasStreetViewLocation getLocation() {
    return new StreetViewLocation(impl.getLocation(jso));
  }

  @Override
  public HasStreetViewTileData getTiles() {
    return new StreetViewTileData(impl.getTiles(jso));
  }

  @Override
  public void setCopyright(String copyright) {
    impl.setCopyright(jso, copyright);
  }

  @Override
  public void setLinks(ArrayList<HasStreetViewLink> links) {
    JsArray<JavaScriptObject> linksJso = (JsArray<JavaScriptObject>) JavaScriptObject.createArray();
    for (HasStreetViewLink link : links) {
      linksJso.push(link.getJso());
    }
    impl.setLinks(linksJso, linksJso);
  }

  @Override
  public void setLocation(HasStreetViewLocation location) {
    impl.setLocation(jso, location.getJso());
  }

  @Override
  public void setTiles(HasStreetViewTileData tiles) {
    impl.setTiles(jso, tiles.getJso());
  }

  @Override
  public JavaScriptObject getJso() {
    return jso;
  }

}
